package com.example.web;

import com.example.feign.MenuFeign;
import com.example.pojo.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/client/menu")
public class ClientMenuController {

    @Autowired
    private MenuFeign menuFeign;

    /**
     * 获取menu服务端口号
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return menuFeign.index();
    }

    /**
     * 查询所有菜单信息
     * @param startIndex
     * @param nums
     * @return
     */
    @GetMapping("/selectAll/{startIndex}/{nums}")
    public List<Menu> selectAllMenu(@PathVariable("startIndex") Integer startIndex,
                                    @PathVariable("nums") Integer nums){

        List<Menu> menuList = menuFeign.selectAllMenu(startIndex, nums);
        return menuList;
    }

    /**
     * 按照任意属性查询菜单信息
     * @param menu
     * @return
     */
    @RequestMapping("/selectByField")
    public Menu selectMenuByField(Menu menu){

        Menu menuByField = menuFeign.selectMenuByField(menu);
        return menuByField;
    }

    /**
     * 查询菜单信息数量
     * @return
     */
    @GetMapping("/selectCount")
    public Integer countMenu(){
        return menuFeign.countMenu();
    }

    /**
     * 更新菜单数据信息
     * @param menu
     * @return
     */
    @RequestMapping("/updateByField")
    public String updateMenuByField(Menu menu){

        menuFeign.updateMenuByField(menu);
        return "更新id="+menu.getId()+"菜单数据成功!";
    }

    /**
     * 新增菜单数据信息
     * @param menu
     * @return
     */
    @RequestMapping("/insertByField")
    public String insertMenuByField(Menu menu){

        menuFeign.insertMenuByField(menu);
        return "插入id="+menu.getId()+"菜单数据成功!";
    }

    /**
     * 删除指定的菜单信息数据
     * @param menu
     * @return
     */
    @RequestMapping("/deleteByField")
    public String deleteMenuByField(Menu menu){

        menuFeign.deleteMenuByField(menu);
        return "删除id="+menu.getId()+"菜单数据成功!";
    }





}
